using System;
using System.Collections.Generic;
using System.Text;

namespace NSimpleDB.Service.VistaDb.QueryProcessing.Compiler.AST
{
    // ItemSetTerm { "INTERSECTION" ItemSetTerm }
    internal class Query
    {
        private List<ItemSetTerm> itemSetTermList;

        public Query(QueryTokenizer tok)
        {
            this.itemSetTermList = new List<ItemSetTerm>();

            tok.Read();
            this.itemSetTermList.Add(new ItemSetTerm(tok));
            while (tok.CurrentTokenType == QueryTokensTypes.UnionOp || 
                   tok.CurrentTokenType == QueryTokensTypes.OrOp)
            {
                tok.Read();
                this.itemSetTermList.Add(new ItemSetTerm(tok));
            }
            if (tok.CurrentTokenType != QueryTokensTypes.EOQ)
                throw new QueryCompilerException(QueryCompilerException.ErrorUnexpectedEndOfQuery, "Query: Error in query! Unexpected end of query. Symbol '{0}' [{1}] found at position {2} in query.", tok.CurrentTokenText, tok.CurrentTokenType.ToString(), tok.CurrentTokenPosition);
        }

        public ItemSetTerm[] ItemSetTermList
        {
            get
            {
                return this.itemSetTermList.ToArray();
            }
        }
    }
}
